package com.hzqy.service.epg;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.hzqy.persistence.dao.epg.AcUserBillDao;
import com.hzqy.web.vo.SysProductVo;
import com.hzqy.web.vo.UserBillVo;
import com.hzqy.web.vo.epg.AcPopupsListVo;
import com.hzqy.web.vo.epg.AcUserBillVo;

@Service
public class AcUserBillServiceBean {

	@Resource
	private AcUserBillDao acUserBillDao;
	
	public int insertUserBill(AcUserBillVo aub) {
		if(aub==null)
			return -1;
		acUserBillDao.insertUserBill(aub);
		return 1;
	}
	
	public Map<String,Object> selectUserBillList(AcUserBillVo aub, int curPage, int pageSize, String repeat){
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_aub_serverid", aub.getF_aub_serverid());
		map.put("f_aub_productid", aub.getF_aub_productid());
		map.put("f_aub_productcode", aub.getF_aub_productcode());
		map.put("f_aub_ordertime", aub.getF_aub_ordertime());
		map.put("f_aub_endtime", aub.getF_aub_endtime());
		map.put("f_aub_udate", aub.getF_aub_udate());
		map.put("f_aub_type", aub.getF_aub_type());
		map.put("repeat", repeat);
		int rowCount= acUserBillDao.selectUserBillCount(map);
		map.put("total", rowCount);
		if(rowCount > 0 && curPage > 0 && pageSize > 0) {
			map.put("firstResult", (curPage-1)*pageSize);
			map.put("maxResults", pageSize);
			
			List<AcUserBillVo> results =acUserBillDao.selectUserBillList(map); 
			map.put("rows", results);
		} else {
			map.put("rows", new ArrayList<UserBillVo>());
		}
		return map;
		
	}
	
	public Map<String,Object> selectUserBillExcelList(AcUserBillVo aub,String repeat) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_aub_serverid", aub.getF_aub_serverid());
		map.put("f_aub_productid", aub.getF_aub_productid());
		map.put("f_aub_productcode", aub.getF_aub_productcode());
		map.put("f_aub_ordertime", aub.getF_aub_ordertime());
		map.put("f_aub_endtime", aub.getF_aub_endtime());
		map.put("f_aub_type", aub.getF_aub_type());
		map.put("f_aub_udate", aub.getF_aub_udate());
		map.put("repeat", repeat);
		Integer rowCount=acUserBillDao.selectUserBillCount(map);
		map.put("total", rowCount);
		if(rowCount > 0) {
			List<AcUserBillVo> results =acUserBillDao.selectUserBillExcelList(map); 
			map.put("rows", results);
		}else {
			map.put("rows", new ArrayList<AcUserBillVo>());
		}
		return map;
	}
	public int insertUserBillExcel(AcUserBillVo aub, String picJson) {
		int flag = 0;
		if(aub==null || aub.getF_aub_serverid()==null) {
			flag = -1;
		}
		if(flag == 0) {
			acUserBillDao.insertUserBill(aub);
			return 1;
		}
		return flag;
	}
	public int updateUserBill(AcUserBillVo aub) {
		return acUserBillDao.updateUserBill(aub);
	}
	
	public List<SysProductVo>  productDetailed() {
		List<SysProductVo> results = acUserBillDao.productDetailed();
		return results;
	}
	//查询该用户是否存在，用户id,产品id产品编号订购时间
	public int selectUserBillCountByUser(AcUserBillVo aub) {
		return acUserBillDao.selectUserBillCountByUser(aub);
	}
	
	public int deleteUserBill(AcUserBillVo aub) {
		return acUserBillDao.deleteUserBill(aub);
	}
	
	public Map<String,Object> selectAcPopupsList(Map<String,Object> map, int curPage, int pageSize){
		Map<String,Object> list = new HashMap<String,Object>();
		int rowCount=acUserBillDao.selectAcPopupsCount(map);
		list.put("total", rowCount);
		if (rowCount > 0) {
			map.put("firstResult", (curPage-1)*pageSize);
			map.put("maxResults", pageSize);
			List<AcPopupsListVo> results = acUserBillDao.selectAcPopupsList(map);
			list.put("rows", results);
		}else {
			list.put("rows", new ArrayList<AcPopupsListVo>());
		}
		return list;
	}
	//查询该用户是否存在，用户id,产品id产品编号订购时间
		public int selectUserBillIsExistByUser(AcUserBillVo aub) {
			return acUserBillDao.selectUserBillIsExistByUser(aub);
		}
}
